import 'package:eh_mobile/common/style/bny_color.dart';
import 'package:eh_mobile/common/utils/index.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import '../../../../common/values/svg_image.dart';

class LightControlBottomitem extends StatefulWidget {
  const LightControlBottomitem(
      {super.key,
      this.selected,
      this.roomName,
      this.deviceName,
      this.tapCallback,
      required this.type,
      required this.index});

  final bool? selected;
  final String? roomName;
  final String? deviceName;
  final VoidCallback? tapCallback;
  final DeviceLListType type;
  final int index;

  @override
  State<LightControlBottomitem> createState() {
    return _LightControlBottomitemState();
  }
}

class _LightControlBottomitemState extends State<LightControlBottomitem> {
  @override
  Widget build(BuildContext context) {
    Color bgColor=widget.selected! ? const Color(0xffF5F5F5) : const Color(0xff444444);;
    Color lightBottomColor =
        widget.selected! ? const Color(0xffFFC400) : Colors.white;
    Color tempBottomColor = widget.selected!
        ? const Color.fromRGBO(69, 69, 69, 1)
        : const Color.fromRGBO(22, 22, 22, 1);
    Color fontColor =
        widget.selected! ? const Color(0xff323232) : const Color(0xffDEDEDE);
    Color circleColor = const Color.fromRGBO(50, 50, 50, 1);
    String switchName = 'assets/images/temp_ic_aircon_on.png';
    if (widget.type == DeviceLListType.temp) {
      if (widget.index == 0 || widget.index == 1) {
        switchName = widget.index == 0
            ? switchName
            : 'assets/images/temp_ic_aircon_off.png';
      } else {
        switchName = widget.index == 2
            ? switchName
            : 'assets/images/temp_ic_aircon_off.png';
      }
    }


    return Container(
      decoration: BoxDecoration(
          color: bgColor,
          borderRadius: BorderRadius.all(const Radius.circular(15.0).r),
          boxShadow: widget.selected!
              ? const <BoxShadow>[
                  BoxShadow(
                    color: Color.fromRGBO(0, 0, 0, 0.5),
                    offset: Offset(0, 3),
                    blurRadius: 25,
                  )
                ]
              : null),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          widget.type == DeviceLListType.light
              ? SvgPicture.asset(
                  SVGImage.cIcLightingSvg,
                  width: 28.w,
                  height: 28.w,
                  color: widget.type == DeviceLListType.light
                      ? lightBottomColor
                      : tempBottomColor,
                )
              : Container(
                  decoration: BoxDecoration(
                    color: circleColor,
                    borderRadius: BorderRadius.circular(21.r),
                  ),
                  padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 8.w),
                  child: Image.asset(
                    switchName,
                    width: 26.w,
                    //  color: circleInnerColor,
                  ),
                ),
          2.sizedBoxHeight,
          SizedBox(
            height: 16.h,
            child: Text(
              widget.roomName ?? '',
              style: 12.ts.copyWith(
                    fontWeight: FontWeight.w600,
                    color: fontColor,
                  ),
            ),
          ),
          SizedBox(
            height: 16.h,
            child: Text(widget.deviceName ?? '',
                style: 12.ts.copyWith(color: fontColor)),
          )
        ],
      ),
    ).onClick(() {
      if (widget.tapCallback != null) {
        widget.tapCallback!();
      }
    });
  }
}
